<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>条件渲染 - 广告</title>
    <style>
        #ad{
            width: 100%;
            height: 100px;
            background: #aef;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        //声明对象, 数据
        let data = {
            isVip: true
        }

        //声明函数
        function ad(){
            //判断
            if(data.isVip){
                return null;
            }
            return <div id="ad">我是广告</div>
        }

        //创建虚拟 DOM
        let vDOM = <header>
                {/*1. 三元运算符  *** */}
                {!data.isVip ? <div id="ad">我是广告</div> : null}    
                {/*2. 逻辑与*/}
                {!data.isVip && <div id="ad">我是广告</div>}
                {/*3. 函数调用    ***  */}
                {ad()}
            </header>

        //渲染
        ReactDOM.render(vDOM, document.querySelector('#root'));
    </script>
</body>
</html>